package com.ihr360.sharedservice.common.dao.impl;

import com.ihr360.sharedservice.common.dao.DataCacheDao;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;
import java.util.Set;

/**
 * Created by Eric on 18/4/10
 */
@Repository
public class DataCacheDaoImpl implements DataCacheDao {

    @Autowired
    private StringRedisTemplate stringRedisTemplate;

    @Override
    public void put(String key, String value) {
        stringRedisTemplate.opsForValue().set(key, value);
    }

    @Override
    public void remove(String key) {
        stringRedisTemplate.delete(key);
    }


    @Override
    public void removeAll(Set<String> keys) {
        stringRedisTemplate.delete(keys);
    }

    @Override
    public void putAll(Map<? extends String, ? extends String> map) {
        stringRedisTemplate.opsForValue().multiSet(map);
    }

    @Override
    public List<String> getAll(List<String> keys) {
        List<String> values = stringRedisTemplate.opsForValue().multiGet(keys);

        return values;
    }

    @Override
    public String get(String key) {
        String value = stringRedisTemplate.opsForValue().get(key);
        return value;
    }
}
